home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / haeberli / libgutil / getset.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  2KB  |  113 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  *    getset - 
  19.  *        Get and set values stored in ~/.gamma
  20.  *
  21.  *                Paul Haeberli - 1984
  22.  *
  23.  */
  24. #include "stdio.h"
  25. #include "port.h"
  26. #include "gl.h"
  27.  
  28. FILE *configopen();
  29.  
  30. float getgamma()
  31. {
  32.     FILE *gamfile;
  33.     float gam;
  34.  
  35.     if ((gamfile = configopen(".gamma","r")) )  {
  36.         if (fscanf(gamfile,"%f\n",&gam) == 1) {
  37.         fclose(gamfile);
  38.         return gam;
  39.     } else 
  40.         fclose(gamfile);
  41.     }
  42.     return 2.2;
  43. }
  44.  
  45. setgamma( gam )
  46. float gam;
  47. {
  48.     FILE *gamfile;
  49.  
  50.     if ((gamfile = configopen(".gamma","w")) == 0) {
  51.     fprintf(stderr,"couldn't open .gamma\n");
  52.     return;
  53.     }
  54.     fprintf(gamfile,"%f\n",gam);
  55.     fclose(gamfile);
  56.     newgamtables();
  57. }
  58.  
  59. getcolorbal(r,g,b)
  60. unsigned int *r, *g, *b;
  61. {
  62.     FILE *cbfile;
  63.  
  64.     if ((cbfile = configopen(".cbal","r")) ) { 
  65.         if (fscanf(cbfile,"%d %d %d\n",r,g,b) == 3) {
  66.         if (*r>255)
  67.         *r = 255;    
  68.         if (*g>255)
  69.         *g = 255;    
  70.         if (*b>255)
  71.         *b = 255;    
  72.             fclose(cbfile);
  73.             return;
  74.         } else 
  75.             fclose(cbfile);
  76.     }
  77.     *r = 255;
  78.     *g = 255;
  79.     *b = 255;
  80.     return;
  81. }
  82.  
  83. setcolorbal(r,g,b)
  84. int r, g, b;
  85. {
  86.     FILE *cbfile;
  87.  
  88.     if ((cbfile = configopen(".cbal","w")) == 0) {
  89.     fprintf(stderr,"couldn't open .cbal\n");
  90.     return;
  91.     }
  92.     fprintf(cbfile,"%d %d %d\n",r,g,b);
  93.     fclose(cbfile);
  94.     newgamtables();
  95. }
  96.  
  97. FILE *configopen( name, mode )
  98. char name[];
  99. char mode[];
  100. {
  101.     char homepath[100];
  102.     FILE *f;
  103.     char *cptr;
  104.  
  105.     cptr = (char *)getenv("HOME");
  106.     if (!cptr)
  107.     return 0;
  108.     strcpy(homepath,cptr);
  109.     strcat(homepath,"/");
  110.     strcat(homepath,name);
  111.     return fopen(homepath,mode);
  112. }
  113.